package com.yunhe.mybatis.web.user;

import com.yunhe.mybatis.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/remove")
public class UserDeleteServlet extends HttpServlet {
    private UserServiceImpl userService = new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setCharacterEncoding("UTF-8");
       //获取删除的请求参数  学生的id
        //先判断

        Integer studentId=null;

        if (null !=req.getParameter("userId")){
            //页面是ID   所以要转换成 Integer
             studentId = Integer.valueOf(req.getParameter("userId"));
        }
        userService.remove(studentId);

        req.getRequestDispatcher("/success.jsp").forward(req,resp);

    }
}
